package com.china08.yxyapi.api.home.activity.lecture;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.db.huodong.YxyHuodongLectureSchoolStatistics;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.statistics.YxyHuodongLectureSchoolStatisticsRepository;

@RestController
@CrossOrigin
public class ActivityLecturedtSchoolController {

    @Autowired
    private YxyHuodongLectureSchoolStatisticsRepository yxyLectureRepository;

    @RequestMapping(value = "/api_yw/home/activity/tea/lecturedt/school/index", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process() {
        RespModel respModel = new RespModel();

        List<YxyHuodongLectureSchoolStatistics> list = yxyLectureRepository
                .findTop10ByAreaIdDistrictOrderByPackCountDesc("451381");
        Integer count = yxyLectureRepository.countByAreaIdDistrict("451381");
        respModel.all = count;
        for (YxyHuodongLectureSchoolStatistics yxy : list) {
            respModel.name.add(yxy.getSchoolNick());
            respModel.data.add(yxy.getPackCount());
        }
        return respModel;
    }

    protected static class ReqModel extends YxyApiReqModel {
    }

    protected static class RespModel extends YxyApiRespModel {
        public List<String> name = new ArrayList<String>();
        public List<Long> data = new ArrayList<>();
        public Integer all = 0;
    }

}
